package com.hytc.mymall.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.hytc.mymall.bean.MerchantConsumptionBean;
import com.hytc.mymall.bean.NoticeBean;
import com.hytc.mymall.viewholder.HomePageViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by allkiss on 2016/12/9
 */
public class HomePageAdapter extends BaseAdapter
{
    private Context context;
    private Map<Integer, View> lmap;
    private List<NoticeBean> noticeList;
    private List<MerchantConsumptionBean> rankLlist;

    public HomePageAdapter(final Context context, final List<MerchantConsumptionBean> rankLlist, final List<NoticeBean> noticeList) {
        this.lmap = new HashMap<Integer, View>();
        this.context = context;
        this.rankLlist = rankLlist;
        this.noticeList = noticeList;
    }

    public int getCount() {
        return 3 + (this.rankLlist.size() + this.noticeList.size());
    }

    public Object getItem(final int n) {
        return null;
    }

    public long getItemId(final int n) {
        return 0L;
    }

    public View getView(final int n, View view, final ViewGroup viewGroup) {
        HomePageViewHolder tag;
        if (this.lmap.get(n) != null) {
            view = this.lmap.get(n);
            tag = (HomePageViewHolder)view.getTag();
        }
        else {
            tag = new HomePageViewHolder();
            if (n == 0 || n == 2 + this.rankLlist.size()) {
                view = View.inflate(this.context, 2130903194, (ViewGroup)null);
                tag.title = (TextView)view.findViewById(2131100312);
                tag.more = (TextView)view.findViewById(2131100313);
            }
            else if (n >= 1 && n < 2 + this.rankLlist.size()) {
                view = View.inflate(this.context, 2130903148, (ViewGroup)null);
                tag.merchantname = (TextView)view.findViewById(2131100164);
                tag.merchantconsumption = (TextView)view.findViewById(2131100165);
            }
            else if (n > 2 + this.rankLlist.size() && n < this.getCount()) {
                view = View.inflate(this.context, 2130903147, (ViewGroup)null);
                tag.notice = (TextView)view.findViewById(2131100163);
            }
            view.setTag((Object)tag);
        }
        if (n == 0) {
            tag.title.setText((CharSequence)this.context.getResources().getString(2131361842));
        }
        else {
            if (n == 2 + this.rankLlist.size()) {
                tag.title.setText((CharSequence)this.context.getResources().getString(2131361844));
                return view;
            }
            if (n >= 1 && n < 2 + this.rankLlist.size()) {
                String text;
                String text2;
                if (n == 1) {
                    text = this.context.getResources().getString(2131361846);
                    text2 = this.context.getResources().getString(2131361847);
                }
                else {
                    final MerchantConsumptionBean merchantConsumptionBean = this.rankLlist.get(n - 2);
                    text = merchantConsumptionBean.merchantName;
                    text2 = merchantConsumptionBean.consumptionAmount;
                }
                tag.merchantname.setText((CharSequence)text);
                tag.merchantconsumption.setText((CharSequence)text2);
                return view;
            }
            if (n > 2 + this.rankLlist.size() && n < this.getCount()) {
                tag.notice.setText((CharSequence)this.noticeList.get(-3 + (n - this.rankLlist.size())).news);
                return view;
            }
        }
        return view;
    }
}
